// 入驻申请
<template>
   <div class="search">
     <Row>
        <Card>
          <Row class="operation">
            <Form inline :label-width="100" ref="searchForm" :model="searchForm" label-position="right">
              <Button @click="getDataList()" icon="md-refresh">刷新</Button>

              <FormItem label="审核状态" prop="checkEnum">
                <Select v-model="searchForm.checkEnum" style="width:180px" clearable>
                  <!-- <Option value=" ">全部</Option> -->
                  <Option value="PRE_CHECK">待审核</Option>
                  <Option value="CHECK_SUCCESS">审核成功</Option>
                  <Option value="CHECK_FAIL">审核失败</Option>
                </Select>
              </FormItem>
              <FormItem label="用户名称" prop="username">
                <Input type="text" v-model="searchForm.username" placeholder="请输入用户名"/>
              </FormItem>
              <FormItem label="手机号" prop="mobile">
                <Input type="text" v-model="searchForm.mobile" placeholder="请输入手机号"/>
              </FormItem>
              <Button @click="handleSearch" type="primary" icon="ios-search" style="margin-left:20px;">搜索</Button>
            </Form>
          </Row>
          <Modal title="查看大图" v-model="visible" class-name="fl-image-modal">
            <img :src="imgUrl" v-if="visible" style="width: 100%">
          </Modal>

          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>

          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>

         </Card>
         <Modal title="审核" v-model="modalVisible2" :mask-closable='false' :width="700">
          <Form ref="userform" :model="userform" :label-width="100" :rules="formValidate">
            <Form-item label="审核状态" prop="checkEnum">
              <Select v-model="userform.checkEnum" style="width:100%">
                <Option value="CHECK_SUCCESS">同意入驻请求</Option>
                <Option value="CHECK_FAIL">驳回入驻请求</Option>
              </Select>
            </Form-item>
            <FormItem label="审核意见" prop="checkAdvice">
              <Input type="textarea" v-model="userform.checkAdvice" placeholder="请输入审核意见" />
            </FormItem>
          </Form>
          <div slot="footer">
            <Button type="text" @click="modalVisible2=false">取消</Button>
            <Button type="primary" :loading="submitLoading" @click="handleSubmit2">提交</Button>
          </div>
        </Modal>
     </Row>
   </div> 
</template>

<script>
import uploadPicThumb from "@/views/my-components/xboot/upload-pic-thumb";
import uploadPicInput from "@/views/my-components/xboot/upload-pic-input";
export default {
  components: {
    uploadPicInput,
    uploadPicThumb
  },
  data(){
    return{ 
      ruleValidate: {
        mobile:[
          { required: true, message: '手机号码不能为空', trigger: 'blur' },
          { type: 'munber', max: 11, message: '格式不正确', trigger: 'blur' }
        ],
      },
      visible:false,
      classdata:[],
      citydata:[],
      total:0,
      loading: true, // 表单加载状态
      data:[],//表单数据
      submitLoading: false, // 添加或编辑提交状态
      modalTitle:'',
      modalVisible:false,  
      modalVisible2:false, 
      searchForm:{
        checkEnum:'',
        username:'',
        id:'',
        mobile:'',
        pageSize:10,
        pageNumber:1
      },
      userform:{
        id:'',
        checkEnum:'',
        checkAdvice:''
      },
      formValidate: {
        checkEnum: [{ required: true, message: "请选择审核状态", trigger: "change" }],
        checkAdvice: [{ required: false, message: "请输入审核原因", trigger: "blur" }]
      },
      formadd:{
        storeType:'',
        username:'',
        mobile:'',
        classificationId:'',
        areaId:'',
        idCardFront:'',
        idCardBack:'',
        businessCard:'',
        longitude:'',
        latitude:'',
        pic:'',
      },
      columns: [
      // 表头
      {
        type: "index",
        width: 60,
        align: "center"
      },
      {
        title: "类型",
        key: "storeType",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "用户名称",
        key: "username",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "联系方式",
        key: "mobile",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "支付宝账号",
        key: "alipayAccount",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "微信账号",
        key: "wechatAccount",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "身份证正面",
        key: "idCardFront",
        minWidth: 120,
        sortable: false,
        render: (h, params) => {
          return h("img", {
            style:{
              'margin-top':'5px',
              'margin-bottom':'5px',
              'border-radius':'4px',
              width:'60px',
              height:'40px',
            },
            attrs:{
              src:params.row.idCardFront,
              onerror:''
            },
            on:{
              click:(e)=>{
                this.handleView(e.srcElement.currentSrc)
              }
            }
          });
        }  
      },
      {
        title: "身份证反面",
        key: "idCardBack",
        minWidth: 120,
        sortable: false,
        render: (h, params) => {
          return h("img", {
            style:{
              'margin-top':'5px',
              'margin-bottom':'5px',
              'border-radius':'4px',
              width:'60px',
              height:'40px',
            },
            attrs:{
              src:params.row.idCardBack,
              onerror:''
            },
            on:{
              click:(e)=>{
                this.handleView(e.srcElement.currentSrc)
              }
            }
          });
        }  
      },
      {
        title: "营业执照",
        key: "businessCard",
        minWidth: 120,
        sortable: false,
        render: (h, params) => {
          return h("img", {
            style:{
              'margin-top':'5px',
              'margin-bottom':'5px',
              'border-radius':'4px',
              width:'60px',
              height:'40px',
              cursor:'pointer'
            },
            attrs:{
              src:params.row.businessCard,
              onerror:''
            },
            on:{
              click:(e)=>{
                this.handleView(e.srcElement.currentSrc)
              }
              }
            });
          }  
        },
        {
          title: "审核状态",
          key: "checkEnum",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "创建时间",
          key: "createTime",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          fixed: "right",
          minWidth: 200,
          render: (h, params) => {
            if (params.row.checkEnum == '待审核') {
              return h("div", [
                h(
                  "Button",
                  {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px"
                    },
                    on: {
                      click: () => {
                        this.edit(params.row);
                      }
                    }
                  },
                  "审核"
                ),
              ]);
            } else {
              return h('span','暂无操作');
            } 
          }
        }
      ],}
    },
    methods:{
      init(){
        this.getDataList()
      },
      handleView(url) {
        this.imgUrl = url;
        this.visible = true;
      },
      getDataList(){
        if (this.searchForm.checkEnum == undefined) {
          this.searchForm.checkEnum = ''
        }
        this.postRequest("/storeAudit/getList",this.searchForm).then(res =>{
          this.loading = false
          if(res.success){
            var arr = res.result.dataResult;
            for(let val of arr){
              for(let i in val){
                (val[i] === null) ? (val[i] = "-") : ""
              }
            }
            this.data = res.result.dataResult;
            this.total = res.result.totalNumber
          } else {
            this.data = [];
            this.total = 0;
          }
        })
      },
      //审核
      edit(v){
        this.userform.id = v.id;
        this.$refs.userform.resetFields();
        this.modalVisible2 = true
      },
      //删除
      remove(v){
        console.log(v)
        let params = {
          ids:v.id
        }
        this.postRequest("storeAudit/removeStoreAudit",params).then(res =>{
          if(res.success){
            this.$Message.success("删除成功")
            this.getDataList()
          }
        })
      },
      //搜索查询
      handleSearch(){
        this.searchForm.pageNumber = 1;
        this.searchForm.pageSize = 10
        this.getDataList()
      },
      //提交
      handleSubmit2(){
        this.$refs.userform.validate(valid => {
          if (valid) {
            this.submitLoading = true
            this.postRequest("/storeAudit/checkStoreAudit",this.userform).then(res =>{
              console.log(res)
              this.submitLoading = false
              if(res.success){ 
                this.$Message.success("提交成功");
                this.getDataList();
                this.modalVisible2 = false
              } else{
                this.$Message.error(res.message) 
                this.modalVisible2 = false
              }
            })
          }
        })
        
      },
      handleSubmit(){
        if(this.formadd.pic !='' || this.formadd.pic.length!=0){
          this.formadd.pic = this.formadd.pic.join(',');
        }
        console.log(this.formadd)
        this.postRequest("/storeAudit/insertOrderUpdateStoreAudit",this.formadd).then(res =>{
          console.log(res)
          if(res.success){
            this.$Message.success('提交成功')
            this.modalVisible = false
            this.$refs.formadd.resetFields()
            this.getDataList()
          }
        })
      },
      changeSort(e) {
        this.searchForm.sort = e.key;
        this.searchForm.order = e.order;
        if (e.order === "normal") {
          this.searchForm.order = "";
        }
        this.getDataList();
      },
      changePage(v) {
        this.searchForm.pageNumber = v;
        this.getDataList();
      },
      changePageSize(v) {
        console.log(v)
        this.searchForm.pageNumber = 1
        this.searchForm.pageSize = Number(v);
        this.getDataList();
      },
      clearSelectAll(){
        this.$refs.searchForm.resetFields()
        this.getDataList()
      },
      //获取分类
      getclasslist(){
      this.postRequest("/classification/getCategoryList").then(res => {
          console.log(res)
          if (res.success) {
            this.classdata = this.getTree(res.result.data);
            console.log(this.classdata)
          }
        });
      },
      //获取城市ID
      getcitylist(){ 
          this.postRequest("/area/getBackAreaList").then(res => {
          this.loading = false;
          console.log(res)
          if (res.success) {
            res.result.data.forEach(function(e) {
              e.value = e.id
              e.label = e.title
              e.children = []
              delete e.id
              delete e.title
              if (e.isParent) {
                e.loading = false;
                e.children = [];
              }
            });
            this.citydata =res.result.data;
          }
        });
      },
      loadData(item,callback) {
        console.log(item)
        let param={
          pid:item.value
        }
        console.log(param)
        this.postRequest("/area/getBackAreaList",param).then(res =>{
          console.log(res)
          if (res.success) {
            res.result.data.forEach(function(e) {
              e.value = e.id
              e.label = e.title
              e.children=[]
              delete e.id
              delete e.title
              if (e.isParent) {
                e.loading = false;
                e.children = [];
              }
            });
            item.children = res.result.data
            callback(item.children);
          }
        });
      },
      handleChangecity(v){
        console.log(v)
        this.formadd.areaId = v[v.length-1]
        console.log(this.formadd.areaId)
      },
      handleChange(v){
        console.log(v)
        this.formadd.classId = v[v.length-1]
        console.log(this.formadd.classId)
      },
      getTree(tree = []) {
        let arr = [];
        if (!!tree && tree.length !== 0) {
          tree.forEach(item => {
            let obj = {};
            obj.value = item.id;
            obj.label= item.title
            obj.children = this.getTree(item.backAreaVOS); // 递归调用
            arr.push(obj);
          });
        }
        return arr;
      },
    },
    mounted(){
        this.init()
    }
}
</script>

<style lang="less">
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>